package jfoo.detailsTable;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;


class StringTableCellRenderer implements TableCellRenderer {
	DetailsTable detailsTable;

	static Color stripe1 = Color.WHITE;
	static Color stripe2 = new Color(246, 249, 254);
	static Color backgroundSelected = new Color(211, 227, 254);
	static Color fontColor1 = new Color(119, 119, 119);
	static Color fontColor2 = new Color(70, 120, 206);
	JLabel leJLabel;

	public StringTableCellRenderer(DetailsTable detailsTable) {
		this.detailsTable = detailsTable;
		leJLabel = new JLabel();
		leJLabel.setOpaque(true);
		leJLabel.setHorizontalTextPosition(2);
	}

	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

		// AudioFile element =(AudioFile)value;
		if (value != null) {
			leJLabel.setText(value.toString());
			leJLabel.setToolTipText(value.toString());
		}

		// leJLabel.setIcon(element.getRepresentation());
		if ((column == 2) || (column == 4)) {
			leJLabel.setForeground(fontColor2);
		} else {
			leJLabel.setForeground(fontColor1);
		}

		if (column < 3) {
			leJLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		} else if (column == 3) {
			leJLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

		} else if (column >= 4) {
			leJLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		}

		if (isSelected) {
			leJLabel.setBackground(backgroundSelected);
		} else {
			if (row % 2 == 0) {
				leJLabel.setBackground(stripe1);
			} else {
				leJLabel.setBackground(stripe2);
			}
		}

		if ((row == detailsTable.getCurrentPlayingIndex()) && (column == 1)) { // to
			// handle
			// a
			// notification
			// that that
			// song is
			// playing
			// leJLabel.setBackground(Color.blue);
			leJLabel.setText(value.toString() + " is in da house");
		}

		return leJLabel;
	}
}